<template>
  <el-dialog :title="title" :visible.sync="sync" :width="width" @close="close">
    <el-tag type="info" v-html="content">
      {{content}}
    </el-tag>
    <p v-if="att.flag">
      <el-button @click="downAtt()" type="text">{{att.name}}</el-button>
    </p>
  </el-dialog>
</template>
<script>
  import qs from 'qs';
  export default {
    data(){
      return {
        title: '合同公告',
        sync: false,
        content: '',
        att: {
          flag: false,
          name: '',
          url: ''
        }
      };
    },
    props: {
      value: {
        type: Boolean
      },
      width: {
        type: String
      },
      url: {
        type: String
      },
      id : {
        type: String
      }
    },
    watch:{
      value(val){
       let params = qs.stringify({id:this.id});
       let _this = this;
       if(val==false){
         return;
       }
       this.axios.post(this.lib.config.host.contract+'/contractmgt/contract/viewNotice',params).
        then(res=>{
          let notice = res.data.resultMap.data;
          let content = '';
          if(notice==null || notice.content==null || notice.content==''){
            content = '没有公告';
            _this.att.flag = false;
          }else{
            content = notice.content;
            if(notice.attFileUrl!=null){
               _this.att.name = notice.attFileName;
               _this.att.url = notice.attFileUrl;
               _this.att.flag = true;
          }}
          _this.content = content; 
          _this.sync = val;
          });
       
      }
    },
    methods:{
      downAtt(){
        this.downloadFile(this.att.url,this.att.name);
      },
      close(){
        this.sync = false;
        this.$emit('input', false);
      }
      
    }
  }
</script>
<style>
</style>
